home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / raid / devRaidParityCheck.c < prev    next >
C/C++ Source or Header  |  1990-11-09  |  7KB  |  231 lines

  1. /* 
  2.  * devRaidParityCheck.c --
  3.  *
  4.  *    This file implements routines for checking the parity.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #include "sync.h"
  18. #include <string.h>
  19. #include "stdio.h"
  20. #include "sprite.h"
  21. #include "fs.h"
  22. #include "dev.h"
  23. #include "devBlockDevice.h"
  24. #include "devRaid.h"
  25. #include "semaphore.h"
  26. #include "stdlib.h"
  27. #include "devRaidUtil.h"
  28. #include "schedule.h"
  29. #include "devRaidProto.h"
  30.  
  31.  
  32. /*
  33.  *----------------------------------------------------------------------
  34.  *
  35.  * Raid_InitiateParityCheck --
  36.  *    
  37.  *    Check the parity beginning at startStripe for numStripe.
  38.  *    If numStripe is negative, all stripes will be checked.
  39.  *    (ctrlData is used by the debug device when debugging in user mode.)
  40.  *
  41.  * Results:
  42.  *    None.
  43.  *
  44.  * Side effects:
  45.  *    Parity is updated.
  46.  *
  47.  *----------------------------------------------------------------------
  48.  */
  49.  
  50. static void InitiateStripeParityCheck();
  51. static void parityCheckReadDoneProc();
  52.  
  53. void
  54. Raid_InitiateParityCheck(raidPtr, startStripe, numStripe, doneProc,clientData,ctrlData)
  55.     Raid    *raidPtr;
  56.     int         startStripe;
  57.     int         numStripe;
  58.     void       (*doneProc)();
  59.     ClientData   clientData;
  60.     int         ctrlData;
  61. {
  62.     RaidReconstructionControl    *reconstructionControlPtr;
  63.     reconstructionControlPtr =
  64.         Raid_MakeReconstructionControl(raidPtr, (int) NIL, (int) NIL,
  65.             (RaidDisk *) NIL, doneProc, clientData, ctrlData);
  66.     reconstructionControlPtr->stripeID = startStripe;
  67.     reconstructionControlPtr->numStripe = numStripe;
  68.     printf("RAID:MSG:Initiating parity check.\n");
  69.     InitiateStripeParityCheck(reconstructionControlPtr);
  70. }
  71.  
  72.  
  73. /*
  74.  *----------------------------------------------------------------------
  75.  *
  76.  * parityCheckDoneProc --
  77.  *
  78.  *    Callback procedure for Raid_InitiateParityCheck.
  79.  *
  80.  * Results:
  81.  *    None.
  82.  *
  83.  * Side effects:
  84.  *    None.
  85.  *
  86.  *----------------------------------------------------------------------
  87.  */
  88. static void
  89. parityCheckDoneProc(reconstructionControlPtr)
  90.     RaidReconstructionControl    *reconstructionControlPtr;
  91. {
  92.     reconstructionControlPtr->doneProc(reconstructionControlPtr->clientData,
  93.         reconstructionControlPtr->status);
  94.     Raid_FreeReconstructionControl(reconstructionControlPtr);
  95. }
  96.  
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * Raid_InitiateParityCheckFailure --
  102.  *
  103.  *    Causes the initialization of the current stripe to fail.
  104.  *
  105.  * Results:
  106.  *    None.
  107.  *
  108.  * Side effects:
  109.  *    Prints an error message.
  110.  *
  111.  *----------------------------------------------------------------------
  112.  */
  113.  
  114. static void
  115. Raid_InitiateParityCheckFailure(reconstructionControlPtr)
  116.     RaidReconstructionControl    *reconstructionControlPtr;
  117. {
  118.     parityCheckReadDoneProc(reconstructionControlPtr, 1);
  119. }
  120.  
  121.  
  122. /*
  123.  *----------------------------------------------------------------------
  124.  *
  125.  * InitiateStripeParityCheck --
  126.  *
  127.  *    Reconstructs the parity on a single stripe.
  128.  *
  129.  * Results:
  130.  *    None.
  131.  *
  132.  * Side effects:
  133.  *    Locks stripe.
  134.  *    Parity is updated.
  135.  *
  136.  *----------------------------------------------------------------------
  137.  */
  138.  
  139. static void
  140. InitiateStripeParityCheck(reconstructionControlPtr)
  141.     RaidReconstructionControl    *reconstructionControlPtr;
  142. {
  143.     Raid           *raidPtr       = reconstructionControlPtr->raidPtr;
  144.  
  145.  
  146.     int                   ctrlData      = reconstructionControlPtr->ctrlData;
  147.     RaidRequestControl *reqControlPtr = reconstructionControlPtr->reqControlPtr;
  148.     char           *readBuf       = reconstructionControlPtr->readBuf;
  149.     char           *parityBuf     = reconstructionControlPtr->parityBuf;
  150.  
  151.     int                stripeID      = reconstructionControlPtr->stripeID;
  152.     int                numStripe     = reconstructionControlPtr->numStripe;
  153.     unsigned            firstSector;
  154.     unsigned            nthSector;
  155.  
  156.     firstSector = StripeIDToSector(raidPtr, stripeID);
  157.     nthSector   = NthSectorOfStripe(raidPtr, firstSector);
  158.     if (stripeID >= raidPtr->numStripe || stripeID < 0 || numStripe == 0) {
  159.     parityCheckDoneProc(reconstructionControlPtr);
  160.     return;
  161.     }
  162.     Raid_SLockStripe(raidPtr, stripeID);
  163.     reqControlPtr->numReq = reqControlPtr->numFailed = 0;
  164.     AddRaidDataRequests(reqControlPtr, raidPtr, FS_READ,
  165.         firstSector, nthSector, readBuf, ctrlData);
  166.     AddRaidParityRequest(reqControlPtr, raidPtr, FS_READ,
  167.         (unsigned) StripeIDToSector(raidPtr, stripeID),
  168.         parityBuf, ctrlData);
  169.     if (reqControlPtr->numFailed == 0) {
  170.     Raid_InitiateIORequests(reqControlPtr,
  171.         parityCheckReadDoneProc,
  172.         (ClientData) reconstructionControlPtr);
  173.     } else {
  174.     Raid_InitiateParityCheckFailure(reconstructionControlPtr);
  175.     }
  176. }
  177.  
  178.  
  179. /*
  180.  *----------------------------------------------------------------------
  181.  *
  182.  * parityCheckReadDoneProc --
  183.  *
  184.  *    Callback procedure for InitiateStripeParityCheck.
  185.  *    Called after the data and parity on a stripe is read.
  186.  *    Checks the parity.
  187.  *
  188.  * Results:
  189.  *    None.
  190.  *
  191.  * Side effects:
  192.  *    None.
  193.  *
  194.  *----------------------------------------------------------------------
  195.  */
  196.  
  197. static void
  198. parityCheckReadDoneProc(reconstructionControlPtr, numFailed)
  199.     RaidReconstructionControl    *reconstructionControlPtr;
  200.     int                  numFailed;
  201. {
  202.     Raid           *raidPtr       = reconstructionControlPtr->raidPtr;
  203.     char           *parityBuf     = reconstructionControlPtr->parityBuf;
  204.     RaidRequestControl *reqControlPtr = reconstructionControlPtr->reqControlPtr;
  205.     int                stripeID      = reconstructionControlPtr->stripeID;
  206.  
  207.     if (numFailed > 0) {
  208.     Raid_ReportParityCheckFailure(reconstructionControlPtr->stripeID);
  209.     reconstructionControlPtr->status = FAILURE;
  210.     } else {
  211.     char           *xorBuf = malloc((unsigned)raidPtr->bytesPerStripeUnit);
  212.     bzero(xorBuf, raidPtr->bytesPerStripeUnit);
  213.     XorRaidRequests(reqControlPtr, raidPtr, xorBuf);
  214. #ifndef NODATA
  215.     bzero(parityBuf, raidPtr->bytesPerStripeUnit);
  216.     if (bcmp(parityBuf, xorBuf, raidPtr->bytesPerStripeUnit) != 0) {
  217.         Raid_ReportParityCheckFailure(stripeID);
  218.         reconstructionControlPtr->status = FAILURE;
  219.     }
  220.     free(xorBuf);
  221. #endif
  222.     }
  223.     if (reconstructionControlPtr->stripeID % 100 == 0) {
  224.     printf("RAID:MSG:%d", reconstructionControlPtr->stripeID);
  225.     }
  226.     Raid_SUnlockStripe(raidPtr, reconstructionControlPtr->stripeID);
  227.     reconstructionControlPtr->stripeID++;
  228.     reconstructionControlPtr->numStripe--;
  229.     InitiateStripeParityCheck(reconstructionControlPtr);
  230. }
  231.